package com.yisu.auction.api.domain.config;

import com.alibaba.fastjson.JSON;
import io.github.xdiamond.client.annotation.OneKeyListener;
import io.github.xdiamond.client.event.ConfigEvent;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2016/8/25.
 */
@Service
public class SystemConfig {

    @Value("${qiniu.access.key}")
    private String qiNiuAccessKey;
    @Value("${qiniu.secret.key}")
    private String qiNiuSecretKey;
    @Value("${qiniu.bucket.name}")
    private String qiNiuBucketName;
    @Value("${qiniu.image.center.host}")
    private String qiNiuImageHost;
    @Value("${yun.pian.message.url}")
    private String yunPianUrl;
    @Value("${yun.pian.api.key}")
    private String yunPianApiKey;
    @Value("${yun.pian.text}")
    private String yunPianText;
    @Value("${auction.job.url}")
    private String auctionJobUrl;
    @Value("${mobile.charge.interfaceUrl}")
    private String mobileChargeInterfaceUrl;
    @Value("${mobile.charge.accountname}")
    private String mobileChargeAccountName;
    @Value("${mobile.charge.password}")
    private String mobileChargePassword;
    @Value("${is.stop.purchase}")
    private boolean isStopPurchase;
    @Value("${api.stock.pingNotifyUrl}")
    private String stockPayNotifyUrl;

    public String getStockPayNotifyUrl() {
        return stockPayNotifyUrl;
    }
    @OneKeyListener(key = "api.stock.pingNotifyUrl")
    public void setStockPayNotifyUrl(ConfigEvent event) {
        try {
            if (event != null) {
                stockPayNotifyUrl = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            stockPayNotifyUrl = null;
        }
    }

    public String getMobileChargeInterfaceUrl() {
        return mobileChargeInterfaceUrl;
    }
    @OneKeyListener(key = "mobile.charge.interfaceUrl")
    public void setMobileChargeInterfaceUrl(ConfigEvent event) {
        try {
            if (event != null) {
                mobileChargeInterfaceUrl = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            mobileChargeInterfaceUrl = null;
        }
    }

    public String getMobileChargeAccountName() {
        return mobileChargeAccountName;
    }
    @OneKeyListener(key = "mobile.charge.accountname")
    public void setMobileChargeAccountName(ConfigEvent event) {
        try {
            if (event != null) {
                mobileChargeAccountName = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            mobileChargeAccountName = null;
        }
    }

    public String getMobileChargePassword() {
        return mobileChargePassword;
    }
    @OneKeyListener(key = "mobile.charge.password")
    public void setMobileChargePassword(ConfigEvent event) {
        try {
            if (event != null) {
                mobileChargePassword = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            mobileChargePassword = null;
        }
    }

    public String getAuctionJobUrl() {
        return auctionJobUrl;
    }

    @OneKeyListener(key = "auction.job.url")
    public void setAuctionJobUrl(ConfigEvent event) {
        try {
            if (event != null) {
                auctionJobUrl = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            auctionJobUrl = null;
        }
    }

    public String getQiNiuAccessKey() {
        return qiNiuAccessKey;
    }

    @OneKeyListener(key = "qiniu.access.key")
    public void setQiNiuAccessKey(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuAccessKey = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuAccessKey = null;
        }
    }

    public String getQiNiuSecretKey() {
        return qiNiuSecretKey;
    }

    @OneKeyListener(key = "qiniu.secret.key")
    public void setQiNiuSecretKey(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuSecretKey = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuSecretKey = null;
        }
    }

    public String getQiNiuBucketName() {
        return qiNiuBucketName;
    }

    @OneKeyListener(key = "qiniu.bucket.name")
    public void setQiNiuBucketName(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuBucketName = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuBucketName = null;
        }
    }

    public String getQiNiuImageHost() {
        return qiNiuImageHost;
    }

    @OneKeyListener(key = "qiniu.image.center.host")
    public void setQiNiuImageHost(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuImageHost = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuImageHost = null;
        }
    }


    public String getYunPianUrl() {
        return yunPianUrl;
    }

    @OneKeyListener(key = "yun.pian.message.url")
    public void setYunPianUrl(ConfigEvent event) {
        try {
            if (event != null) {
                yunPianUrl = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            yunPianUrl = null;
        }
    }


    public String getYunPianApiKey() {
        return yunPianApiKey;
    }

    @OneKeyListener(key = "yun.pian.api.key")
    public void setYunPianApiKey(ConfigEvent event) {
        try {
            if (event != null) {
                yunPianApiKey = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            yunPianApiKey = null;
        }
    }

    public String getYunPianText() {
        return yunPianText;
    }

    @OneKeyListener(key = "yun.pian.text")
    public void setYunPianText(ConfigEvent event) {
        try {
            if (event != null) {
                yunPianText = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            yunPianText = null;
        }
    }


    public boolean isStopPurchase() {
        return isStopPurchase;
    }
    
    @OneKeyListener(key = "is.stop.purchase")
    public void setStopPurchase(ConfigEvent event) {
        try {
            if (event != null) {
                isStopPurchase = Boolean.valueOf(String.valueOf(JSON.parseObject(event.toString()).get("value")));
            }
        } catch (Exception ex) {
            isStopPurchase = false;
        }
    }
}
